import React from 'react';
import Editor from '@monaco-editor/react';
import { autoJSCompletions } from './autojs-completions';

const CodeEditor: React.FC = () => {
  const handleEditorDidMount = (editor: any, monaco: any) => {
    // 添加Auto.js API自动完成
    monaco.languages.registerCompletionItemProvider('javascript', {
      provideCompletionItems: () => ({
        suggestions: autoJSCompletions
      })
    });
  };

  return (
    <Editor
      height="100%"
      defaultLanguage="javascript"
      defaultValue="// 在此输入Auto.js脚本\n"
      theme="vs-light"
      options={{
        minimap: { enabled: true },
        fontSize: 14,
        lineHeight: 21,
        padding: { top: 10, bottom: 10 },
        scrollBeyondLastLine: false,
        folding: true,
        lineNumbers: 'on',
        renderLineHighlight: 'line',
        suggestOnTriggerCharacters: true,
        wordBasedSuggestions: 'currentDocument',
        quickSuggestions: { other: true, comments: true, strings: true },
        automaticLayout: true
      }}
      onMount={handleEditorDidMount}
    />
  );
};

export default CodeEditor; 